#ifndef FILTERPROXYMODEL_H
#define FILTERPROXYMODEL_H

#include <QSortFilterProxyModel>

class ProductListModel;

// "items to buy" filter
class ItemsToBuyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
    ItemsToBuyModel(QAbstractItemModel &sourceModel, QObject* parent = NULL);
protected:
    bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const;
};

// "items you have" filter
class ItemsYouHaveModel : public ItemsToBuyModel
{
Q_OBJECT
public:
    ItemsYouHaveModel(QAbstractItemModel &sourceModel, QObject* parent = NULL);
protected:
    bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const;
};

class FilterProxyModel : public QSortFilterProxyModel
{
    Q_OBJECT
    Q_PROPERTY(bool isApplicationBusy READ isApplicationBusy NOTIFY applicationBusyChanged)

public:
    explicit FilterProxyModel(QObject *parent = 0);

    /*!
      Interface for QML side.
      Buy product request for item with \a index.
     */
    Q_INVOKABLE void buy(int index);

    /*!
      Interface for QML side.
      Requests IAP client to restore all unlocked products.
     */
    Q_INVOKABLE void restoreProducts();

    /*!
      Interface for QML side.
      Requests IAP client for user info.
     */
    Q_INVOKABLE void getUserInfo();

    /*!
      Reads product catalog
    */
    Q_INVOKABLE void readDRMCatalog();

    Q_INVOKABLE void resetPurchases();
    /*!
      Property accessor.
    */
    bool isApplicationBusy() const;

signals:
    /*!
      Signal emitted when product list model busy state has changed.
    */
    void applicationBusyChanged();

    /*!
      Signal emitted when product buy request has completed.
    */
    void appPurchaseCompleted(QVariant status);

public slots:
    /*!
      Slot for catching model updated signal from underlying model.
    */
    void modelUpdated();

    /*!
      Slot for catching busy state change signal from underlying model.
    */
    void modelBusyChanged();

    /*!
      Slot for catching buy complete signal from underlying model.
    */
    void purchaseCompleted(bool status);

private:
    /*!
      Base class virtual method implementation.
    */
    bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
};

#endif // FILTERPROXYMODEL_H
